//
//  PlayBarDetailView.m
//  CoolFM
//
//  Created by 曹曹 on 16/9/13.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "PlayBarDetailView.h"
#import "CFMacro.h"
#import "PlayBarTableViewCell.h"
#import "GXNetTool.h"
#import "PlayerModel.h"
#import "PlayerList.h"

#define kPlayBarTableViewCell @"PlayBarTableViewCell"

@interface PlayBarDetailView () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *lineView;

@end

@implementation PlayBarDetailView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setUp];
        
    }
    return self;
}
- (void)setPlayerModel:(PlayerModel *)playerModel {
    _playerModel = playerModel;
    [self.tableView reloadData];
}
- (void)setUp {
    /**
     * 标题label
     */
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, CGRectGetWidth([UIScreen mainScreen].bounds), 20)];
    label.text = @"播放列表";
    label.textAlignment = NSTextAlignmentLeft;
    label.font = kFont11;
    [self addSubview:label];
    UIView *seperator = [[UIView alloc] initWithFrame:CGRectMake(0, 20, CGRectGetWidth([UIScreen mainScreen].bounds), 1)];
    seperator.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:seperator];
#warning 这里给了固定的cell高度 64
    _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, 2, 64)];
    _lineView.backgroundColor = kDefaultColor;
    [self addSubview:_lineView];
    /**
     * tableView
     */
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(2, 21, CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetHeight(self.bounds) - 20)];
    _tableView.tableHeaderView = [UIView new];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    kTalbleViewRegisterNib(@"PlayBarTableViewCell", kPlayBarTableViewCell);
    [self addSubview:_tableView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (_playerModel) {
        return _playerModel.program_list.count;
    }
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    PlayBarTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kPlayBarTableViewCell];
    cell.list = _playerModel.program_list[indexPath.row];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 64;
}

@end
